// routes/cards/findAllByGroup.js
const express = require('express');
const pool = require('../../config/pool'); // 使用连接池
const router = express.Router();
const isAdmin = require('../../middleware/isAdmin');

// 创建卡片 只有管理员才可以
router.delete('/:id', isAdmin, (req, res) => {
    const id = req.params.id;
    // 校验id是否是int类型
    if (!id || isNaN(id)) {
        return res.status(400).json({
            code: 0,
            message: 'id必须是数字',
            success: false
        });
    }
    const sql = 'DELETE FROM cards WHERE id = ?';
    pool.query(sql, [id], (err, result) => {
        if (err) {
            res.status(500).json({
                code: 0,
                message: err.message,
                success: false
            });
        }
        res.status(200).json({
            code: 1,
            message: '卡片删除成功',
            success: true
        });
    });
});

module.exports = router;